<script lang="ts" setup>
import { ref } from "vue";

const dataList = ref<any>([
  {
    name: "早教",
    sort: "50",
    isLeaf: false
  },
  {
    name: "早教2",
    sort: "50",
    isLeaf: true
  },
  {
    name: "编程",
    sort: "50",
    isLeaf: false
  }
]);

const modalVisible = ref(false);

const handleAction = (action: string) => {
  if (action === 'add') {
    modalVisible.value = true;
  }
};
</script>

<template>
  <umrp-container bg-color="#f2f2f2" height="100%" padding="16px" :gap="16">
    <umrp-breadcrumb :items="['商品管理', '商品分类']"></umrp-breadcrumb>
    <umrp-card>
      <umrp-table :data="dataList" :action-bar="true" @action="handleAction">
        <template #columns>
          <umrp-table-column title="分类名称" slot-name="name"></umrp-table-column>
          <umrp-table-column title="分类图标" slot-name="icon"></umrp-table-column>
          <umrp-table-column title="分类排序" data-index="sort"></umrp-table-column>
          <umrp-table-column title="操作" slot-name="action" :width="220"></umrp-table-column>
        </template>
        <template #action>
          <umrp-space :size="10">
            <umrp-button type="primary" @click="modalVisible = true">新增子项</umrp-button>
            <umrp-button type="primary" @click="modalVisible = true">编辑</umrp-button>
            <umrp-popconfirm message="您确认删除么？">
              <umrp-button type="danger">移除</umrp-button>
            </umrp-popconfirm>
          </umrp-space>
        </template>
        <template #name="{ record }">
          <umrp-container direction="horizonal" :gap="10">
            <umrp-icon name="right" :style="{ opacity: record.isLeaf ? 0 : 1 }"></umrp-icon>
            <umrp-text>{{ record.name }}</umrp-text>
          </umrp-container>
        </template>
        <template #icon>
          <umrp-image :width="32" :height="32"></umrp-image>
        </template>
      </umrp-table>
    </umrp-card>
    <umrp-modal v-model:visible="modalVisible" :width="500">
      <umrp-container padding="24px 0">
        <umrp-form>
          <umrp-form-item label="分类名称">
            <umrp-input></umrp-input>
          </umrp-form-item>
          <umrp-form-item label="分类排序">
            <umrp-input-number :default-value="50"></umrp-input-number>
          </umrp-form-item>
        </umrp-form>
      </umrp-container>
    </umrp-modal>
  </umrp-container>
</template>